<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../layui/css/layui.css?v=1" media="all">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script src="../../layui/layui.js?v=1" charset="utf-8"></script>
    <script src="../../js/config.js?v=1"></script>
    <script src="../../js/public.js?v=1"></script>
    <script src="../../js/function.js?v=1"></script>
    <link rel="stylesheet" href="../../css/public.css?v=1">
    <link rel="stylesheet" href="../../css/patient/add.css?v=1">
    <style>
        .layui-form-select dl {
            min-height: 150px;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="table-title">
            <p>新病例登记</p>
        </div>
        <div class="add-container">
            <div class="add-step">
                <ul class="step-list">
                    <li class="step-item" style="float:left;">
                        <img src="../../img/step1_lanse.png">
                        <p>基本信息</p>
                    </li>
                    <li class="step-item">
                        <img src="../../img/step2_huise.png">
                        <p>垂体疾病类型</p>
                    </li>
                    <li class="step-item" style="float:right;">
                        <img src="../../img/step3_huise.png">
                        <p>生成个性化问卷</p>
                    </li>
                    <div class="clear"></div>
                </ul>
                <div class="add-step-hr"></div>
            </div>
            <div class="baseinfo-box">
                <div class="baseinfo-box-title">
                    <p>垂体疾病类型</p>
                </div>

                <form class="layui-form">
                    <div class="baseinfo-item">
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label">联系手机</div>
                            <div class="layui-input-inline">
                                <input type="text" name="cell" maxlength="11" class="layui-input" placeholder="请输入手机号">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" name="smscode" class="layui-input" placeholder="请输入验证码">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <div class="layui-input-inline">
                                <button class="get-code" type="button">获取验证码</button>
                            </div>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="baseinfo-item">
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label">患者姓名</div>
                            <div class="layui-input-inline">
                                <input type="text" name="name" class="layui-input" placeholder="请输入患者姓名">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label" style="letter-spacing: 25px;text-align: center;">性别</div>
                            <div class="layui-input-inline">
                                <button class="sex-btn" type="button" data-val="0">男</button>
                                <button class="sex-btn" type="button" data-val="1">女</button>
                                <input type="hidden" name="sex">
                            </div>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="baseinfo-item">
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label">出生日期</div>
                            <div class="layui-input-inline">
                                <input type="text" name="bday" class="layui-input" id="bday" placeholder="请选择出生日期" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label" style="letter-spacing: 25px;text-align: center;">民族</div>
                            <div class="layui-input-inline">
                                <select name="ethnicity">
                                <option value="">请选择</option>
                                <option value="汉族">汉族</option>
                                <option value="蒙古族">蒙古族</option>
                                <option value="回族">回族</option>
                                <option value="藏族">藏族</option>
                                <option value="维吾尔族">维吾尔族</option>
                                <option value="苗族">苗族</option>
                                <option value="彝族">彝族</option>
                                <option value="壮族">壮族</option>
                                <option value="布依族">布依族</option>
                                <option value="朝鲜族">朝鲜族</option>
                                <option value="满族">满族</option>
                                <option value="侗族">侗族</option>
                                <option value="瑶族">瑶族</option>
                                <option value="白族">白族</option>
                                <option value="土家族">土家族</option>
                                <option value="哈尼族">哈尼族</option>
                                <option value="哈萨克族">哈萨克族</option>
                                <option value="傣族">傣族</option>
                                <option value="黎族">黎族</option>
                                <option value="僳僳族">僳僳族</option>
                                <option value="佤族">佤族</option>
                                <option value="畲族">畲族</option>
                                <option value="高山族">高山族</option>
                                <option value="拉祜族">拉祜族</option>
                                <option value="水族">水族</option>
                                <option value="东乡族">东乡族</option>
                                <option value="纳西族">纳西族</option>
                                <option value="景颇族">景颇族</option>
                                <option value="柯尔克孜族">柯尔克孜族</option>
                                <option value="土族">土族</option>
                                <option value="达斡尔族">达斡尔族</option>
                                <option value="仫佬族">仫佬族</option>
                                <option value="羌族">羌族</option>
                                <option value="布朗族">布朗族</option>
                                <option value="撒拉族">撒拉族</option>
                                <option value="毛南族">毛南族</option>
                                <option value="仡佬族">仡佬族</option>
                                <option value="锡伯族">锡伯族</option>
                                <option value="阿昌族">阿昌族</option>
                                <option value="普米族">普米族</option>
                                <option value="塔吉克族">塔吉克族</option>
                                <option value="怒族">怒族</option>
                                <option value="乌孜别克族">乌孜别克族</option>
                                <option value="俄罗斯族">俄罗斯族</option>
                                <option value=鄂温克族"">鄂温克族</option>
                                <option value="德昂族">德昂族</option>
                                <option value="保安族">保安族</option>
                                <option value="裕固族">裕固族</option>
                                <option value="京族">京族</option>
                                <option value="塔塔尔族">塔塔尔族</option>
                                <option value="独龙族">独龙族</option>
                                <option value="鄂伦春族">鄂伦春族</option>
                                <option value="赫哲族">赫哲族</option>
                                <option value="门巴族">门巴族</option>
                                <option value="珞巴族">珞巴族</option>
                                <option value="基诺族">基诺族</option>
                            </select>
                            </div>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="baseinfo-item">
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label">身份证号</div>
                            <div class="layui-input-inline">
                                <input type="text" maxlength="18" name="sfzid" class="layui-input" placeholder="请输入身份证号">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label" style="letter-spacing: 25px;text-align: center;">籍贯</div>
                            <div class="layui-input-inline">
                                <!--<input type="text" name="birthplace" class="layui-input" placeholder="请输入籍贯">-->
                                <select class="layui-select birthplace" name="ancestral_home">
                                <option>请选择</option>
                                <option>北京</option>
                                <option>上海</option>
                            </select>
                            </div>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="baseinfo-item">
                        <div class="layui-form-item layui-inline">
                            <div class="layui-form-label" style="width:180px;">家庭成员有无类似疾病？</div>
                            <div class="layui-input-inline" style="width:auto;">
                                <button class="family_like_has" type="button" data-val="1">是</button>
                                <button class="family_like_has" type="button" data-val="0">否</button>
                                <input type="hidden" name="family_like_has">
                            </div>
                            <div class="layui-input-inline family_like_has_type_name" style="display: none;">
                                <input type="text" class="layui-input" name="family_like_has_type_name">
                            </div>
                            <div class="clear"></div>
                        </div>
                    </div>
                    <div class="baseinfo-item-btn">
                        <a href="javascript:;" lay-submit="" lay-filter="nextBtn"><button type="button">下一步</button></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="fixed-container change-center-container" id="yijiaru">
        <div class="fixed-main">
            <div class="fixed-title">
                <p>提示</p>
                <i class="layui-icon layui-icon-close fixed-main-close"></i>
            </div>
            <div class="fixed-form">
                <p class="fixed-tip">患者已经在<span class="hosp_name"></span>本医院加入垂体项目，是否查看档案？</p>
                <form class="layui-form">
                    <div class="fixed-form-item-confirm">
                        <button type="button" class="yijiaru_confirm">是</button>
                        <button type="button" style="background:#4777E7;color:white;" class="cancel_yijiaru">否</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="fixed-container change-center-container" id="yijiaru_other">
        <div class="fixed-main">
            <div class="fixed-title">
                <p>提示</p>
                <i class="layui-icon layui-icon-close fixed-main-close"></i>
            </div>
            <div class="fixed-form">
                <p class="fixed-tip other_msg">患者已经在<span class="hosp_name"></span>医院加入垂体项目，是否查看档案？</p>
                <form class="layui-form">
                    <div class="fixed-form-item-confirm">
                        <button type="button" class="yijiaru_other_confirm">是</button>
                        <button type="button" style="background:#4777E7;color:white;" class="cancel_yijiaru_other">否</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="fixed-container change-center-container" id="yizhuce">
        <div class="fixed-main">
            <div class="fixed-title">
                <p>提示</p>
                <i class="layui-icon layui-icon-close fixed-main-close"></i>
            </div>
            <div class="fixed-form">
                <p class="fixed-tip">患者<span class="patient_name"></span>已注册，是否加入垂体项目？</p>
                <form class="layui-form">
                    <div class="fixed-form-item-confirm">
                        <button type="button" class="yizhuce_confirm">是</button>
                        <button type="button" style="background:#4777E7;color:white;" class="cancel_yizhuce">否</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
<script>
    var maxtime = 60;
    var timer;
    //更换手机号获取验证码
    function CountSendSms() {
        if (maxtime >= 0) {
            --maxtime;
            $(".get-code").html(maxtime + '秒后获取');
            $(".get-code").attr('disabled', true);
        } else {
            $(".get-code").html('获取验证码');
            $(".get-code").attr('disabled', false);
            clearInterval(timer);
        }
    }
    $(document).ready(function() {
        /*var height = $(window).height() - 2;
        $('.container').height(height);
        $('.add-container').height(height - 51);*/
        layui.use(['element', 'form', 'layer', 'laydate', 'laypage'], function() {
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var laypage = layui.laypage;

            //允许最大时间
            var now = new Date();
            var year = parseInt(now.getFullYear());
            var month = parseInt(now.getMonth() + 1);
            var day = now.getDate();
            var max_date = year + '-' + month + '-' + day;
            //出生日期
            laydate.render({
                elem: '#bday',
                'max': max_date,
                trigger: 'click'
            });

            //输入手机号获取验证码，已加入
            $('.cancel_yijiaru').click(function() {
                $('#yijiaru').hide();
            })
            $('.yijiaru_confirm').click(function() {
                    //已加入垂体项目，跳转用户信息
                    ajax_post(configUrl.patientJoin, {
                        user_id: getLocalStorage('patient_id')
                    }, (res) => {
                        console.log(res);
                        if (res.status == 0) {
                            layer.msg('加入成功', {
                                icon: 1,
                                time: 1000
                            }, function() {
                                window.location.href = './patient_info.html';
                            });
                        } else {
                            layer.msg('加入失败，请重试', {
                                icon: 5,
                                time: 1500
                            });
                        }
                    })
                })
                //输入手机号获取验证码，在本院已注册
            $('.cancel_yizhuce').click(function() {
                $('#yizhuce').hide();
            })
            $('.yizhuce_confirm').click(function() {
                    //已注册，加入垂体项目
                    /*$('input[name=cell]').val(patient_info.cell);
                    $('input[name=name]').val(patient_info.name);
                    $('input[name=sex]').val(patient_info.sex);
                    if(patient_info.sex == 0){
                        $('.baseinfo-item .sex-btn:nth-child(1)').addClass('sex-btn-checked');
                        $('.baseinfo-item .sex-btn:nth-child(1)').siblings('button').removeClass('sex-btn-checked');
                    }else{
                        $('.baseinfo-item .sex-btn:nth-child(2)').addClass('sex-btn-checked');
                        $('.baseinfo-item .sex-btn:nth-child(2)').siblings('button').removeClass('sex-btn-checked');
                    };
                    $('input[name=bday]').val(patient_info.bday);
                    $('input[name=ethnicity]').val(patient_info.ethnicity);
                    $('input[name=sfzid]').val(patient_info.sfzid);
                    $('input[name=ancestral_home]').val(patient_info.ancestral_home);*/
                    ajax_post(configUrl.patientJoin, {
                        user_id: getLocalStorage('patient_id')
                    }, (res) => {
                        if (res.status == 0) {
                            layer.msg('加入成功', {
                                icon: 1,
                                time: 1000
                            }, function() {
                                window.location.href = './patient_info.html';
                            });
                        } else {
                            layer.msg('加入失败，请重试', {
                                icon: 5,
                                time: 1500
                            });
                        }
                    })
                })
                //输入手机号获取验证码，已在其他医院加入垂体
            $('.cancel_yijiaru_other').click(function() {
                $('#yijiaru_other').hide();
            })
            $('.yijiaru_other_confirm').click(function() {
                //已在其他医院加入，请求加入本医院api
                /*$('input[name=cell]').val(patient_info.cell);
                $('input[name=name]').val(patient_info.name);
                $('input[name=sex]').val(patient_info.sex);
                if(patient_info.sex == 0){
                    $('.baseinfo-item .sex-btn:nth-child(1)').addClass('sex-btn-checked');
                    $('.baseinfo-item .sex-btn:nth-child(1)').siblings('button').removeClass('sex-btn-checked');
                }else{
                    $('.baseinfo-item .sex-btn:nth-child(2)').addClass('sex-btn-checked');
                    $('.baseinfo-item .sex-btn:nth-child(2)').siblings('button').removeClass('sex-btn-checked');
                };
                $('input[name=bday]').val(patient_info.bday);
                $('input[name=ethnicity]').val(patient_info.ethnicity);
                $('input[name=sfzid]').val(patient_info.sfzid);
                $('input[name=ancestral_home]').val(patient_info.ancestral_home);*/
                ajax_post(configUrl.patientJoinHosp, {
                    user_id: getLocalStorage('patient_id')
                }, (res) => {
                    if (res.status == 0) {
                        layer.msg('加入成功', {
                            icon: 1,
                            time: 1000
                        }, function() {
                            window.location.href = './patient_info.html';
                            //$('#yijiaru_other').hide();
                            //form.render();
                        });
                    } else {
                        layer.msg('加入失败，请重试', {
                            icon: 5,
                            time: 1500
                        });
                    }
                })
            });
            var patient_info = '';
            $('.get-code').click(function() {
                    //先验证是否注册
                    var cell = $("input[name=cell]").val();
                    if (cell == '') {
                        layer.msg('请输入手机号', {
                            icon: 5,
                            time: 1500
                        });
                        return false;
                    }
                    var loadindex = layer.load();
                    ajax_get(configUrl.patientCheckSms, {
                            cell: cell
                        }, (res) => {
                            layer.close(loadindex);
                            console.log(res);
                            if (res.status == 0) {
                                if (res.data.is_register == 1 && res.data.is_join == 0) {
                                    patient_info = res.data;
                                    saveLocalStorage('patient_id', res.data.id);
                                    $('.patient_name').text(res.data.name + '(' + res.data.cell + ')');
                                    $('#yizhuce').show();
                                } else if (res.data.is_join == 1 && res.data.is_register == 1 && res.data.in_other_hosp_join == 0) {
                                    patient_info = res.data;
                                    saveLocalStorage('patient_id', res.data.id)
                                    $('.host_name').text(res.data.name + '(' + res.data.cell + ')' + res.data.hosp_name);
                                    $('#yijiaru').show();
                                } else if (res.data.is_join == 1 && res.data.is_register == 1 && res.data.in_other_hosp_join == 1) {
                                    patient_info = res.data;
                                    saveLocalStorage('patient_id', res.data.id)
                                    $('#yijiaru_other .fixed-tip').text(res.data.msg);
                                    $('#yijiaru_other').show();
                                } else {
                                    layer.msg('发送成功', {
                                        icon: 1,
                                        time: 1000
                                    }, function() {
                                        timer2 = setInterval('CountSendSms()', 1000);
                                    });
                                }
                            } else {
                                layer.msg(res.msg, {
                                    icon: 5,
                                    time: 1500
                                });
                            }
                        })
                        //再验证是否加入垂体项目
                        //$('#yijiaru').show();
                        //都过了之后发送验证码
                })
                //关闭弹窗
            $('.fixed-main-close').click(function() {
                $('.fixed-container').hide();
            })

            $('.sex-btn').click(function() {
                if ($(this).hasClass('sex-btn-checked')) {
                    console.log('true')
                } else {
                    $(this).addClass('sex-btn-checked');
                    $(this).siblings().removeClass('sex-btn-checked');
                    var value = $(this).attr('data-val');
                    $(this).siblings('input').val(value);
                }
            });

            $('.family_like_has').click(function() {
                var value = $(this).attr('data-val');
                console.log(value)
                if ($(this).hasClass('family_like_has_checked')) {
                    $(this).removeClass('family_like_has_checked');
                    $(this).siblings('input').val('');
                    $('.family_like_has_type_name').hide();
                } else {
                    $(this).addClass('family_like_has_checked');
                    $(this).siblings().removeClass('family_like_has_checked');
                    var value = $(this).attr('data-val');
                    $('input[name=family_like_has]').val(value);
                    if (value == 1) {
                        $('.family_like_has_type_name').show();
                    } else {
                        $('.family_like_has_type_name').hide();
                        $('input[name=family_like_has_type_name]').val('');
                    }
                    form.render();
                }
            });

            //下一步
            form.on('submit(nextBtn)', function(data) {
                var params = data.field;
                if (patient_info == '') {
                    params.is_new = '1';
                }
                console.log(params);
                if (params.cell == '') {
                    layer.msg('请输入手机号', {
                        icon: 5,
                        time: 1500
                    });
                    return false;
                }
                if (params.is_new !== 1) {
                    if (params.smscode == '') {
                        layer.msg('请输入验证码', {
                            icon: 5,
                            time: 1500
                        });
                        return false;
                    }
                }
                if (params.name == '') {
                    layer.msg('请输入患者姓名', {
                        icon: 5,
                        time: 1500
                    });
                    return false;
                }
                if (params.sex == '') {
                    layer.msg('请选择性别', {
                        icon: 5,
                        time: 1500
                    });
                    return false;
                }
                if (params.bday == '') {
                    layer.msg('请选择出生日期', {
                        icon: 5,
                        time: 1500
                    });
                    return false;
                }
                if (params.ethnicity == '') {
                    layer.msg('请选择民族', {
                        icon: 5,
                        time: 1500
                    });
                    return false;
                }
                if (params.sfzid == '') {
                    layer.msg('请输入身份证号', {
                        icon: 5,
                        time: 1500
                    });
                    return false;
                }
                if (params.ancestral_home == '') {
                    layer.msg('请输入籍贯', {
                        icon: 5,
                        time: 1500
                    });
                    return false;
                }
                var loadindex = layer.load();
                ajax_post(configUrl.patientSave, params, (res) => {
                    console.log(res);
                    layer.close(loadindex);
                    if (res.status == 0) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            saveLocalStorage('patient_id', res.data.user_id);
                            window.location.href = './pituitary_type.html';
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 1500
                        });
                    }
                })
            });
            getRegion(form);

            function getRegion(form) {
                //获取地市
                ajax_get(configUrl.getRegion, '', (res) => {
                    console.log(res);
                    $('.birthplace').empty();
                    var str = '<option value="">请选择</option>';
                    $('.birthplace').append(str);
                    $.each(res.data, function(index, item) {
                        var str2 = '<option value="' + item.id + '">' + item.name + '</option>';
                        $('.birthplace').append(str2);
                    });
                    form.render();
                })
                form.render();
            }
        })
    })
</script>

</html>